<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8"/>
    <title>首页</title>
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<div>
    <p>用户名：<span id="userName"></span></p>
    <p>应用id：<span id="clientId"></span></p>
    <p>token：<span id="accessToken"></span></p>
    <p><input type="button" value="登出" onclick="logout()"/></p>
</div>
<script>
    //应用id
    let clientId = 'app';

    window.onload = function () {
        let accessToken = localStorage.getItem('access_token');
        if (accessToken) {//已登录
            let username = localStorage.getItem('username');
            $('#accessToken').html(accessToken);
            $('#userName').html(username);
            $('#clientId').html(clientId);
        } else {//未登录
            localStorage.setItem("visitUri", window.location.href);
            window.location = 'http://127.0.0.1:8080/oauth.html';
        }
    };

    function logout() {
        let accessToken = localStorage.getItem('access_token');
        localStorage.removeItem('access_token');
        localStorage.removeItem('username');
        // window.location = 'http://127.0.0.1:9900/api-uaa/remove/token?redirect_uri=http://127.0.0.1:8080/oauth.html&access_token=' + accessToken;
        window.location = 'http://127.0.0.1:9900/api-uaa/logout?redirect_uri=http://127.0.0.1:8080/oauth.html&access_token=' + accessToken;
    }
</script>
</body>
</html>
